Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[begin]: event_factory should cancel Close context in case of reselect #1519

Merged

Conversation

glazychev-art
Copy link
Contributor

@glazychev-art glazychev-art commented Oct 2, 2023

Description

Chain elements in Closes can rely on the context and its timeout. Therefore, after the operation is completed, the context must be canceled.

Issue link

How Has This Been Tested?

  • Added unit testing to cover
  • Tested manually
  • Tested by integration testing
  • Have not tested

Types of changes

  • Bug fix
  • New functionality
  • Documentation
  • Refactoring
  • CI

…eselect option

Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
@codecov
Copy link

codecov bot commented Oct 2, 2023

Codecov Report

All modified lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@256d2cc). Click here to learn what that means.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1519   +/-   ##
=======================================
  Coverage        ?   67.02%           
=======================================
  Files           ?      257           
  Lines           ?    12257           
  Branches        ?        0           
=======================================
  Hits            ?     8215           
  Misses          ?     3531           
  Partials        ?      511           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -101,13 +101,13 @@ func (f *eventFactoryClient) Request(opts ...Option) <-chan error {
request := f.request.Clone()
if o.reselect {
ctx, cancel := f.ctxFunc()
defer cancel()
_, _ = f.client.Close(ctx, request.GetConnection(), f.opts...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,
ran the test on my side, works fine

Just a small question about the source of the issue: Am I correct in understanding that the original problem occurs because the cancel() for Request was run before the cancel() for Close, because they both use the defer directive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. Close can use the context somewhere in its goroutine.
And this goroutine will be alive as long as this context is alive. But after the parent Close is completed, this is unnecessary and even dangerous - the goroutine can use the same data as the subsequent Request.
Therefore, before the Request, we need to complete Close call (including its goroutines)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for explanation!

@denis-tingaikin denis-tingaikin merged commit 836a51c into networkservicemesh:main Oct 16, 2023
17 checks passed
nsmbot pushed a commit to networkservicemesh/sdk-kernel that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-map-ip-k8s that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-csi-driver that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nsc-init that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-ipam-vl3 that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-cluster-info-k8s that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nse-remote-vlan that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/sdk-k8s that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nsmgr that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-registry-memory that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-admission-webhook-k8s that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-registry-proxy-dns that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nsmgr-proxy that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nse-vfio that referenced this pull request Oct 16, 2023
…k@main

PR link: networkservicemesh/sdk#1519

Commit: 836a51c
Author: Artem Glazychev
Date: 2023-10-16 16:32:00 +0700
Message:
  - event_factory should cancel Close context before Request in case of reselect option (#1519)
Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants